package com.sino.struts2;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sino.bean.Qxkw;
import com.sino.business.IBasicInfoService;
import com.sino.business.IPatentManageQxkwService;
import com.sino.business.IPatentManageService;
import com.sino.business.IPatentManageStatService;
import com.sino.business.IStaticDataService;
import com.sino.business.service.LoginInfo;
import com.sino.model.BasicInfoModel;
import com.sino.model.QueryModel;
import com.sino.util.CreatQueryCondition;
import com.sino.util.PageControl;
import com.sino.util.SysParameter;

public class QueryAction extends ActionSupport {
	private QueryModel queryModel;//

	private IStaticDataService staticDateService;// 基础数据

	private IBasicInfoService basicInfoService;

	private IPatentManageService ipatentManageService;// 专利管理

	IPatentManageQxkwService patentManageQxkw;// 区县科委

	private IPatentManageStatService patentManageStatService;

	private String basicinfo$qxkw;

	private List sbrStatList;// 申报人

	private int patentAllCount;// 专利总数

	private LoginInfo logininfo;

	private String page;// 当前页

	private List<BasicInfoModel> basicInfoList;

	private String pageStr;

	private List qxkwList;// 区科委

	private String qxkwStr;// 区县科委链接字符串

	private List bigqxkwList;// 市委办局

	private List otherqxkwList;// 其他

	private List qxkwStatList;// 推荐单位统计

	private String qxkwTitle = "";

	private String bm_basicinfo$sbr;

	private String bigqxkw;

	private String qxkw;

	private String otherqxkw;

	private List userList;

	private String qxkz = "0000";

	private String sbr;
	
	private String isqualified;

	public String getSbr() {
		return sbr;
	}

	public void setSbr(String sbr) {
		this.sbr = sbr;
	}

	public String getQxkz() {
		return qxkz;
	}

	public void setQxkz(String qxkz) {
		this.qxkz = qxkz;
	}

	public List getUserList() {
		return userList;
	}

	public void setUserList(List userList) {
		this.userList = userList;
	}

	public String getBigqxkw() {
		return bigqxkw;
	}

	public void setBigqxkw(String bigqxkw) {
		this.bigqxkw = bigqxkw;
	}

	public String getOtherqxkw() {
		return otherqxkw;
	}

	public void setOtherqxkw(String otherqxkw) {
		this.otherqxkw = otherqxkw;
	}

	public String getQxkw() {
		return qxkw;
	}

	public void setQxkw(String qxkw) {
		this.qxkw = qxkw;
	}

	public String getBasicinfo$qxkw() {
		return basicinfo$qxkw;
	}

	public void setBasicinfo$qxkw(String basicinfo$qxkw) {
		this.basicinfo$qxkw = basicinfo$qxkw;
	}

	public String basicInfoQuery() {

		// this.setQxkwStr(this.ipatentManageService.getQxkwLink(this.getStaticDateService().findQxkwList()));//获得区县字符串链接表
		Map session = ActionContext.getContext().getSession();
		LoginInfo logininfo = (LoginInfo) session.get("logininfo");
		String qqxkw = logininfo.getQxkw();

		PageControl pageControl = new PageControl();// 翻页控制类
		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类

		HttpServletRequest request = ServletActionContext.getRequest();
		creatQueryCondition.initializtion(request);// 初始化查询条件

		pageControl.setPage(page);// 设置当前页
		pageControl.setPageSize(20);// 设置每页显示的记录数量

		pageControl
				.setRowCount(this.getIpatentManageService()
						.getBasicInfoPageCount(
								creatQueryCondition.getHqlWhere(), qqxkw));// 设置总记录数
		int startRow = (pageControl.getPage() - 1) * pageControl.getPageSize();// 开始行数
		int pageSize = pageControl.getPageSize();// 每页显示的数量
		pageStr = pageControl.getPageInfo("basicInfoQuery.action?qxkw="
				+ basicinfo$qxkw, creatQueryCondition.getCondition());
		basicInfoList = this.getIpatentManageService().getBasicInfoPageList(
				startRow, pageSize, creatQueryCondition.getHqlWhere(), qqxkw);// 分页查询考生信息

		bigqxkwList = this.getStaticDateService().findQxkwList("10");
		qxkwList = this.getStaticDateService().findQxkwList("20");
		otherqxkwList = this.getStaticDateService().findQxkwList("30");

		Qxkw qxkwtitle = this.ipatentManageService.getQxkwById(basicinfo$qxkw);

		this.setBasicinfo$qxkw(basicinfo$qxkw);

		qxkwTitle = qxkwtitle.getName() + "专利基本信息列表";
		this.setBasicInfoList(basicInfoList);
		this.setPageStr(pageStr);

		this.setBigqxkw(bigqxkw);

		this.setQxkw(qxkw);
		this.setOtherqxkw(otherqxkw);
		if (qqxkw.equals("0000")) {

			return "bigsuccess";
		} else {

			return "success";
		}

	}

	public String basicInfoQueryByQxkw() {
		Map session = ActionContext.getContext().getSession();
		LoginInfo logininfo = (LoginInfo) session.get("logininfo");
		String qqxkw = logininfo.getQxkw();
		String hqlWhere="";
        if("1".equals(isqualified))
        {
        	hqlWhere=" basicinfo.isqualified=1 and basicinfo.year="+ SysParameter.CURRENT_YEAR+" ";
        }
        else if("0".equals(isqualified))
        {
        	hqlWhere=" (basicinfo.isqualified=0 or basicinfo.isqualified is null) and basicinfo.year="+ SysParameter.CURRENT_YEAR+" ";
        }
		PageControl pageControl = new PageControl();// 翻页控制类
		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类

		HttpServletRequest request = ServletActionContext.getRequest();
		creatQueryCondition.initializtion(request);// 初始化查询条件

		pageControl.setPage(page);// 设置当前页
		pageControl.setPageSize(20);// 设置每页显示的记录数量

		pageControl.setRowCount(this.getIpatentManageService()
				.getBasicInfoPageCount(hqlWhere, this.getLogininfo().getQxkw()));// 设置总记录数
		int startRow = (pageControl.getPage() - 1) * pageControl.getPageSize();// 开始行数
		int pageSize = pageControl.getPageSize();// 每页显示的数量
		if (null != this.getLogininfo().getQxkw()) {
			pageStr = pageControl.getPageInfo(
					"basicInfoQueryByQxkw.action?isqualified="+isqualified+"&logininfo.qxkw="
							+ this.getLogininfo().getQxkw(), "");
			Qxkw qxkwtitle = this.ipatentManageService.getQxkwById(this
					.getLogininfo().getQxkw());
			if(null!=qxkwtitle.getName())
			{
				qxkwTitle = qxkwtitle.getName() + "专利基本信息列表";
			}
			else{
				qxkwTitle = "专利基本信息列表";
			}
			
		} else {
			pageStr = pageControl
					.getPageInfo("basicInfoQueryByQxkw.action?isqualified="+isqualified, "");
			qxkwTitle = "专利基本信息列表";
		}
		basicInfoList = this.getIpatentManageService().getBasicInfoPageList(
				startRow, pageSize, hqlWhere, this.getLogininfo().getQxkw());// 分页查询考生信息

		

		this.setBasicInfoList(basicInfoList);
		this.setPageStr(pageStr);

		return SUCCESS;

	}

	public String userQuery() {

		// this.setQxkwStr(this.ipatentManageService.getQxkwLink(this.getStaticDateService().findQxkwList()));//获得区县字符串链接表
		Map session = ActionContext.getContext().getSession();
		LoginInfo logininfo = (LoginInfo) session.get("logininfo");
		String qqxkw = logininfo.getQxkw();

		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类
		HttpServletRequest request = ServletActionContext.getRequest();
		creatQueryCondition.initializtion(request);// 初始化查询条件

		userList = this.getIpatentManageService().getUser(qxkw,
				creatQueryCondition.getHqlWhere());
		this.setUserList(userList);
		this.setQxkz(this.qxkz);
		return SUCCESS;

	}

	public String qxkwQuery() {
		Map session = ActionContext.getContext().getSession();
		LoginInfo logininfo = (LoginInfo) session.get("logininfo");

		patentAllCount = this.getPatentManageStatService()
				.getPatentStatAllCount();
		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类
		HttpServletRequest request = ServletActionContext.getRequest();
		creatQueryCondition.initializtion(request);// 初始化查询条件

		qxkwList = this.getPatentManageQxkw().getQxkwByName(
				creatQueryCondition.getHqlWhere());

		return SUCCESS;

	}

	public String qxkwStatQuery() {
		patentAllCount = this.getPatentManageStatService()
				.getPatentStatAllCount();
		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类
		HttpServletRequest request = ServletActionContext.getRequest();
		creatQueryCondition.initializtion(request);// 初始化查询条件
		qxkwStatList = this.patentManageStatService
				.getPatentStatByQxkw1(creatQueryCondition.getHqlWhere());
		return SUCCESS;
	}

	public String sbrQuery() {
		patentAllCount = this.getPatentManageStatService()
				.getPatentStatAllCount();
		String hql = "basicinfo.sbr like '%" + bm_basicinfo$sbr + "%'";

		sbrStatList = this.getPatentManageStatService().getPatentStatBySbrName(
				hql);

		this.setUserList(sbrStatList);
		this.setQxkz(this.qxkz);

		return SUCCESS;

	}

	public String sbrUnitQuery() {
		patentAllCount = this.getPatentManageStatService()
				.getPatentStatAllCount();

		String hql = "basicinfo.sbr like '%" + bm_basicinfo$sbr + "%'";
		System.out.println(hql);
		sbrStatList = this.getPatentManageStatService().getPatentStatBySbrName(
				hql);

		this.setUserList(sbrStatList);
		this.setQxkz(this.qxkz);

		return SUCCESS;

	}

	public QueryModel getQueryModel() {
		return queryModel;
	}

	public void setQueryModel(QueryModel queryModel) {
		this.queryModel = queryModel;
	}

	public List<BasicInfoModel> getBasicInfoList() {
		return basicInfoList;
	}

	public void setBasicInfoList(List<BasicInfoModel> basicInfoList) {
		this.basicInfoList = basicInfoList;
	}

	public IBasicInfoService getBasicInfoService() {
		return basicInfoService;
	}

	public void setBasicInfoService(IBasicInfoService basicInfoService) {
		this.basicInfoService = basicInfoService;
	}

	public IPatentManageService getIpatentManageService() {
		return ipatentManageService;
	}

	public void setIpatentManageService(
			IPatentManageService ipatentManageService) {
		this.ipatentManageService = ipatentManageService;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getPageStr() {
		return pageStr;
	}

	public void setPageStr(String pageStr) {
		this.pageStr = pageStr;
	}

	public IStaticDataService getStaticDateService() {
		return staticDateService;
	}

	public void setStaticDateService(IStaticDataService staticDateService) {
		this.staticDateService = staticDateService;
	}

	public List getQxkwList() {
		return qxkwList;
	}

	public void setQxkwList(List qxkwList) {
		this.qxkwList = qxkwList;
	}

	public String getQxkwStr() {
		return qxkwStr;
	}

	public void setQxkwStr(String qxkwStr) {
		this.qxkwStr = qxkwStr;
	}

	public String getQxkwTitle() {
		return qxkwTitle;
	}

	public void setQxkwTitle(String qxkwTitle) {
		this.qxkwTitle = qxkwTitle;
	}

	public List getBigqxkwList() {
		return bigqxkwList;
	}

	public void setBigqxkwList(List bigqxkwList) {
		this.bigqxkwList = bigqxkwList;
	}

	public List getOtherqxkwList() {
		return otherqxkwList;
	}

	public void setOtherqxkwList(List otherqxkwList) {
		this.otherqxkwList = otherqxkwList;
	}

	public IPatentManageQxkwService getPatentManageQxkw() {
		return patentManageQxkw;
	}

	public void setPatentManageQxkw(IPatentManageQxkwService patentManageQxkw) {
		this.patentManageQxkw = patentManageQxkw;
	}

	public IPatentManageStatService getPatentManageStatService() {
		return patentManageStatService;
	}

	public void setPatentManageStatService(
			IPatentManageStatService patentManageStatService) {
		this.patentManageStatService = patentManageStatService;
	}

	public List getSbrStatList() {
		return sbrStatList;
	}

	public void setSbrStatList(List sbrStatList) {
		this.sbrStatList = sbrStatList;
	}

	public String getBm_basicinfo$sbr() {
		return bm_basicinfo$sbr;
	}

	public void setBm_basicinfo$sbr(String bm_basicinfo$sbr) {
		this.bm_basicinfo$sbr = bm_basicinfo$sbr;
	}

	public List getQxkwStatList() {
		return qxkwStatList;
	}

	public void setQxkwStatList(List qxkwStatList) {
		this.qxkwStatList = qxkwStatList;
	}

	public int getPatentAllCount() {
		return patentAllCount;
	}

	public void setPatentAllCount(int patentAllCount) {
		this.patentAllCount = patentAllCount;
	}

	public LoginInfo getLogininfo() {
		return logininfo;
	}

	public void setLogininfo(LoginInfo logininfo) {
		this.logininfo = logininfo;
	}

	/**
	 * @return the isqualified
	 */
	public String getIsqualified() {
		return isqualified;
	}

	/**
	 * @param isqualified the isqualified to set
	 */
	public void setIsqualified(String isqualified) {
		this.isqualified = isqualified;
	}
	

}
